<template>
  <div>
    <div style="display: flex;justify-content: center;margin-top: 30px">
      <el-card style="width: 80%;margin: 10px">
        <div style="display: flex;border-bottom: 2px solid #8c8c8c">
          <div style="flex: 1;height: 50px;font-size: 25px">累计订单数：<span style="color: #409EFF">{{ count }}</span>
          </div>
        </div>
        <div style="display: flex;align-items: center;justify-content: center;margin-top: 10px">
        </div>
      </el-card>
    </div>
    <div style="display: flex;align-items: center;justify-content: center;">
      <el-card style="width: 80%;margin-top: 30px">
        <div style="height: 50px;font-size: 25px">酒店日收入</div>
        <el-table :data="income" stripe
                  :header-cell-style="{backgroundColor:'aliceblue',color:'#666'}" style="border-radius: 10px">
          <el-table-column prop="hotel_name" label="酒店名"></el-table-column>
          <el-table-column prop="day" label="日期"></el-table-column>
          <el-table-column prop="income" label="收入 "></el-table-column>
        </el-table>
        <div style="margin: 10px 0">
          <el-pagination
              @current-change="handleCurrentChange"
              :current-page="pageNum"
              :page-sizes="[100, 200, 300, 400]"
              :page-size="pageSize"
              layout="total,  prev, pager, next"
              :total="total">
          </el-pagination>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
export default {
  name: "dailyIncome",
  data() {
    return {
      dataToKeep: '',
      user: JSON.parse(localStorage.getItem('user') || '{}'),
      hotel: [],
      hotelData: {},
      income: [],
      pageNum: 1,
      pageSize: 5,
      total: 0,
      hotel_id: "",
      hotel_name: "",
      count: 0,
      status: ['待支付', '已预约', '入住', '退房', '续房'],
    };
  },
  methods: {
    load_business_id() {
      this.$request.post('/hotel_search/', {
        "business_id": this.user.id,
      }).then(res => {
        if (res.code === '200') {
          this.hotel = res.data.hotel_list;
          const length = this.hotel.length;
          this.hotel_id = this.hotel[length - 1].id;
          this.hotelData = this.hotel[length - 1]
          this.load()
          console.log("yyttgg", this.hotelData.status)
          if (this.hotelData.status === "已通过") {
            this.Status = true
            console.log("yyttgg", this.Status)
          }
        } else if (res.code === '501') {
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    load() {
      console.log("xxxxxxx", this.hotel_id)
      this.$request.post('/daily_income_list/',
          {
            "hotel_id": this.hotel_id,
            "hotel_name": this.hotel_name,
            "page_id": this.pageNum,
            "page_size": this.pageSize,
          }).then(res => {
        if (res.code === '200') {
          this.income = res.data.income_list
          this.total = res.data.item_amount
          console.log(res.data)
          this.loadList()
        } else if (res.code === '501') {
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    loadList() {
      this.$request.post('/num_classified_order/',
          {
            "business_id": this.user.id,
            "status": this.status,
          }).then(res => {
        if (res.code === '200') {
          this.count = res.data.amount
          console.log(res.data)
        } else if (res.code === '501') {
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    handleCurrentChange(pageNum) {
      this.load(pageNum)
    },
    // reset() {
    //   this.hotel_name = ''
    //   this.load()
    // },
  },
  created() {
    this.load_business_id()
  },
}
</script>


<style scoped>

</style>